<?php
/********************************************************************************
 * File: index.php
 * Desc: The main page shows one photo along with the photos description, EXIF
 *       data and comments.
 * Args: id - int optional
 *          The photo id to display.  If none, most recent photo is shown.
 *
 * Change   Date        By          Description
 * 1        05/13/2007  mcarruth    Created
 ********************************************************************************/
require_once("inc/header.inc");

echo "<script type='text/javascript' src='js/mootools.js'></script>\n";
	
if (!$_GET['id']) {
   $photos = $f->photos_search(array("user_id"=>$config_flickrUserId, "extras"=>"original_format,date_taken", "per_page"=>"1", "page"=>"1"));
   $id = $photos['photo'][0]['id'];
}
else {
   $id = $_GET['id'];
}

$info = $f->photos_getInfo($id);
$exif = $f->photos_getExif($id);
$context = $f->photos_getContext($id);
$prev = $context['prevphoto']['id'];
$next = $context['nextphoto']['id'];
$comments = $f->photos_comments_getList($id);
$date = getdate(strtotime($info['dates']['taken']));

foreach ($exif['exif'] as $exifItem) {
   switch ($exifItem['label']) {
      case "Model": // label="Model"
         $model = $exifItem['clean'] ? $exifItem['clean'] : $exifItem['raw'];
         break;
      case "Exposure": // label="Exposure"
         $exposure = $exifItem['clean'] ? $exifItem['clean'] : $exifItem['raw'];
         break;
      case "Aperture": // label="Aperture"
         $aperture = $exifItem['clean'] ? $exifItem['clean'] : $exifItem['raw'];
         break;
      case "ISO Speed": // label="ISO Speed"
         $speed = $exifItem['clean'] ? $exifItem['clean'] : $exifItem['raw'];
         break;      
   }
}

echo "<div id='page_header'>\n";
echo "   <span id='page_title'>" . $info['title'] . "</span>\n";
echo "   <span id='page_nav'>\n";
echo "      <a href='index.php?id=" . $prev . "'>prev </a>\n";
echo "      <a href='index.php?id=" . $next . "'>next</a>\n";
echo "   </span>\n";
echo "</div>\n";
echo "<div id='page'>\n";
echo "   <a href='index.php?id=" . $context['prevphoto']['id'] . "' alt='" . $info['title']  . "'>\n";
echo "      <img class='photo' src='" . $f->buildPhotoURL($info, "Original") . "' title='" . $info['title'] . "' alt='" . $info['title']  . "' />\n";
echo "   </a>\n";
echo "</div>\n";

echo "<div id='page_meta'>\n";
echo "   <span style='float:left'>" . $date[month] . " " . $date[mday] . ", " . $date[year] . "</span>\n";
echo "   <span style='float:right'>\n";
echo "      <a href='#' onclick='slider.toggle();'>Info & Comments (". $info['comments'] . ")</a>\n";
echo "   </span>\n";
echo "</div>\n";

echo "<div id='info_comments'>\n";

// description
if ($info['description']) {
   echo    "<div id='description'><h2>description</h2>" . $info['description'] . "</div>\n";
}

// exif
echo    "<div id='exif'><h2>exif</h2>\n";
echo       "Model: " . $model . "<br/>\n";
echo       "Exposure: " . $exposure . "<br/>\n";
echo       "Aperture: " . $aperture . "<br/>\n";
echo       "Speed: " .  $speed . "<br/>\n";
echo    "</div>\n";

// comments
if ($comments['comment']) {
   echo    "<div id='comments'><h2>comments</h2>\n";
   foreach ($comments['comment'] as $comment) {
      echo $comment['authorname'] . " says:<br/>\n";
      echo $comment['_content'] . "<br/><br/>\n";      
   }
echo    "</div>\n";
}

echo    "<br/><a href='" . $info['urls']['url'][0]['_content'] . "'>Leave a comment</a>\n";

echo "</div>\n";

echo "<script>var slider = new Fx.Slide('info_comments', {duration: 500});slider.hide();</script>\n";

require_once("inc/footer.inc"); 

?>
